
import util._
import java.awt.image.BufferedImage

object ComplexPlane 
{
	val HEIGHT = 500
	val WIDTH = 500	
	var image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB)
	var rmin = -2.0
  var rmax = 2.0 
  var imin = -2.0
  var imax = 2.0
	var ar = 1.0
  var ai = 1.0
	var c = Complex(0.0, 0.0)
	
	def  getImage(): BufferedImage =
	{
		image
	}
	
	def  reset(): Unit =
	{
		c = Complex(0.0, 0.0)
		ar = 1.0
        ai = 1.0
		
	}

	def ptoc(x: Int, y: Int) =
	{
		
		var mr = ar/WIDTH*(rmax - rmin)
		var mi = -ai/HEIGHT*(imax - imin)
		var rn = mr*(x - WIDTH/2) + c.real
		var in = mi*(y - HEIGHT/2) + c.imag
		
		Complex(rn, in)
	}
	
	def setCenter(x:Int, y:Int ): Unit =
	{
		c = ptoc(x, y);
	}
	
	def getCenter(): Complex =
	{
		c 
	}
	
	def setScale(realAxis: Double, imaginaryAxis: Double ): Unit =
	{
		ar = realAxis
		ai = imaginaryAxis
	}
	
	def getRealAxisScale(): Double =
	{
		ar
	}
	
	def getImaginaryAxisScale(): Double =
	{
		ai
	}
}
